
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){vue
            var app4 = new Vue({
                el: '#app-4',
                data: {
                    username:'',
                    age:'',
                    todos: [
                        { name: 'FFX',age:'20' ,time:new Date()},
                        { name: '学习 ',age:'22',time:new Date()}
                    ]
                },
                methods: {
                    addpeople: function () {
                        this.todos.push({name: this.username,age:this.age,time:new Date()})

                    },
                    removeall: function () {
                        this.todos=[]
                    },
                    remove:function(index){
                        this.todos.splice(index,1)
                    },
                    resetting: function () {
                        this.todos=[ { name: 'FFX',age:'20',time:new Date() },
                            { name: '学习 ',age:'22',time:new Date() }]
                    }
                },
                filters:{
                    hhmmss:function(val){
                        return (val.getHours()+":"+val.getMinutes()+":"+val.getSeconds())
                    }
                }
            })

        }
    </script>
</head>

<body>


</div>
<div id="app-4">
    <input v-model="username">
    <input v-model="age">
    <button v-on:click="addpeople">添加</button>
    <button v-on:click="resetting">重置</button>
    <button v-on:click="removeall">删除所有</button>
    <table border="1px">
        <tr><th>序号</th><th>名字</th><th>年龄</th><th>添加时间</th><th>操作</th></tr>
        <tr  v-for="(todo,index) in todos">
            <td>{{ index+1 }}</td>
            <td >{{ todo.name }}</td>
            <td >{{ todo.age }}</td>
            <td>{{todo.time|hhmmss}}</td>
            <td><button v-on:click="remove(index)">删除</button></td>
        </tr>
    </table>
</div>
</body>
</html>